<?php

/**
 * Formbuilder class.
 *
 * @author hcderaad
 * @package PhpDocGtk
 */
class PhpDocGtk_Form extends GtkTable {
	
	/**
	 * The forms elements.
	 * 
	 * @var array
	 */
	protected $_elements;
	
	/**
	 * The forms label.
	 * 
	 * @var string
	 */
	protected $_label;
	
	/**
	 * Constructor
	 */
	public function __construct() {
		
		parent::__construct();
	}
	
	/**
	 * Adds an element to the form
	 * 
	 * @param $id The elements id.
	 * @param $type The type of element (text,checkbox,etc)
	 * @param $label The label for the element.
	 * @param $value The form elements value.
	 * @return PhpDocGtk_Form
	 */
	public function addElement($id,$element) {
		if(empty($this->_elements[$id])) {
			$this->_elements[$id] = $element;
		}
		return $this;
	}
	
	/**
	 * Returns the element with the given id.
	 * 
	 * @param $id
	 * @return PhpDocGtk_Form_Element
	 */
	public function getElement($id) {
		if(empty($this->_elements[$id])) {
			throw new PhpDocGtk_Form_Exception('No element set with id: ' . $id);
		}
		return $this->_elements[$id];
	}
	
	/**
	 * Returns the form element values.
	 * 
	 * @return array
	 */
	public function getValues() {
		$values = array();
		foreach($this->_elements as $id => $element) {
			$values[$id] = $element->getValue;
		}
		return $values;
	}
	
	/**
	 * Sets the forms label.
	 * 
	 * @param string $label
	 * @return PhpDocGtk_Form;
	 */
	public function setLabel($label) {
		$this->_label = $label;
		return $this;
	}
	
	/**
	 * Returns the forms label.
	 * 
	 * @return string
	 */
	public function getLabel() {
		return $this->_label;
	}
}
?>